package opertation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * 删除书籍
 */
public class DeleteOpertation implements IOPertation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的书名 ！！！");
        String name = scanner.nextLine();
        int sizeof = bookList.getBooksSizeof();
        int i = 0;
        for (; i < sizeof; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                break;
            }
        }
        if(i == sizeof) {
            System.out.println("没有对应图书 删除失败 ！！！");
            return ;
        }
        for (int j = i; j < sizeof - 1; j++) {
            Book book = bookList.getBook(j+1);
            bookList.setBook(j,book);
        }
        bookList.setBooksSizeof(sizeof - 1);
        System.out.println("删除成功 ！！！");
    }
}

